<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3_5_1-2-数据对象绑定class</title>
</head>

<body>


    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

    <style>
        .red {
            color: red;
            font-size: 2em;
        }

        .blue {
            color: blue;
        }
    </style>

    <div id="app">
        <h1>数据对象</h1>
        <div :class="style">示例文案</div>
        <button @click="btn">改变样式{{ style.blue ? "为红" : "为蓝" }}</button>
    </div>

    <script>
        const App = {
            data() {
                return {
                    //作为数据对象
                    style: {
                        blue: true,
                        red: false,
                    },
                };
            },
            methods: {
                btn() {
                    (this.style.blue = !this.style.blue),
                        (this.style.red = !this.style.red);
                },
            },
        };
        Vue.createApp(App).mount("#app");
    </script>
</body>

</html>